<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.global.js"></script>
    <style>
        .demo {
            font-family: sans-serif;
            border: 1px solid #eee;
            border-radius: 2px;
            padding: 20px 30px;
            margin-top: 1em;
            margin-bottom: 40px;
            user-select: none;
            overflow-x: auto;
        }
    </style>
</head>

<body>

    <div id="blog-posts-events-demo" class="demo">
        <div :style="{ fontSize: postFontSize + 'em' }">
            <blog-post v-for="post in posts" :key="post.id" :title="post.title" @enlarge-text="postFontSize += 0.1"
                 @enlarge-text-by-value="enlargeTextBy">
            </blog-post>
        </div>
    </div>

    <script>
        const app = Vue.createApp({
            data() {
                return {
                    posts: [
                        { id: 1, title: 'My journey with Vue' },
                        { id: 2, title: 'Blogging with Vue' },
                        { id: 3, title: 'Why Vue is so fun' }
                    ],
                    postFontSize: 1
                }
            },
            methods:{
                enlargeTextBy(value){
                    this.postFontSize += value
                }
            }
        })

        app.component('blog-post', {
            props: ['title'],
            emits: ['enlargeText', 'enlargeTextByValue'],
            data() {
                return {
                    fontSizeOffset: 0.5
                }
            },
            template: `
            <div class="blog-post">
            <h4>{{ title }}</h4>
            <button @click="$emit('enlargeText')">
                Enlarge text by 0.1
            </button>

            <button @click="$emit('enlargeTextByValue',fontSizeOffset)">
                Enlarge text by 0.5
            </button>
            </div>
        `
        })

        app.mount('#blog-posts-events-demo')
    </script>

</body>

</html>